<?php
/**
 * @Author: zhaojun(13040@qq.com)
 * @Date:   2018-08-18 16:40:16
 * @Last Modified by:   zhaojun
 * @Last Modified time: 2022-03-26 22:10:32
 */

namespace app\admin\model;
use app\common\model\BaseModel;

class SystemHistmenu extends BaseModel {
	// 设置数据表（不含前缀）
	//protected $name = '';

	// 定义时间戳字段名
	protected $createTime = '';
	protected $updateTime = '';

	public function countSearch($map) {
		return $this->where($map)->count();
	}

	public function search($map, $limitStr="0,0", $orderBy='') {
		list($offset, $limit) = explode(",", $limitStr);
		$data = $this->where($map)->order('create_time asc')->limit($offset, $limit)->select();
		$data = $data->toArray(); //转换为数组
		return $this->parseSearch($data);
	}

	protected function parseSearch($data) {
		$ftpWeb = config('app.ftp_web');
		$isopen_config = config('engineeconfig.isopen_config');

		$list = $ids = array();
		foreach ($data as $key => $value) {
			//通用解析
			//$value['create_time_show'] = $value['create_time'] ? date("Y-m-d H:i:s", $value['create_time']) : '';
			//$value['state_show'] = isset($value['state']) ? $isopen_config[$value['state']] : '';
			//$value['picurl'] = $value['picurl'] ? $ftpWeb.$value['picurl'] : '';
			//通用解析

			$module = $value['module'];
			$controller = $value['controller'];
			$action = $value['action'];
			$parameter = $value['parameter'];
			if ($parameter) {
				$value['url'] = url("{$module}/{$controller}/{$action}?{$parameter}");
			} else {
				$value['url'] = url("{$module}/{$controller}/{$action}");
			}

			$list[$value['id']] = $value;
			$ids[$value['id']] = $value['id'];
		}
		return [$list, $ids];
	}

	protected function parseInfo($info) {
		$ftpWeb = config('app.ftp_web');
		$isopen_config = config('engineeconfig.isopen_config');

		//通用解析
		//$info['create_time_show'] = $info['create_time'] ? date("Y-m-d H:i:s", $info['create_time']) : '';
		//$info['state_show'] = isset($info['state']) ? $isopen_config[$info['state']] : '';
		//$info['picurl'] = $info['picurl'] ? $ftpWeb.$info['picurl'] : '';
		//通用解析

		return $info;
	}

}